package com.truthbean.log.util;

/**
 * @author TruthBean
 * @since 0.0.1
 */
public class MsgHelper {
    public static String format(String msg, Object... params) {
        StringBuilder result = new StringBuilder();
        if (msg != null) {
            String[] splits = msg.split("\\{}");
            result = new StringBuilder(splits[0]);
            Object[] newParams = new Object[splits.length];
            if (params != null) {
                int length;
                if (params.length < splits.length) {
                    length = params.length;
                } else {
                    length = splits.length;
                }
                System.arraycopy(params, 0, newParams, 0, length);
            }

            result.append(newParams[0]);
            if (splits.length > 1) {
                for (int i = 1; i < splits.length; i++) {
                    result.append(splits[i]).append(newParams[i]);
                }
            }
        }
        return result.toString();
    }
}